package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Leavetype;
import com.restaurant.service.LeavetypeService;

public class LeavetypeServiceImpl implements LeavetypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Leavetype addOrModify( Leavetype objLeavetype ) {
       return ( Leavetype ) hibernateTemplate.merge( objLeavetype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Leavetype deleteRecord( Leavetype objLeavetype ) {
       hibernateTemplate.delete( objLeavetype );
       return objLeavetype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Leavetype modifyRecord( Leavetype objLeavetype ) {
       return ( Leavetype ) hibernateTemplate.merge( objLeavetype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Leavetype> loadAll() {
       return (List<Leavetype>)hibernateTemplate.findByNamedQuery( "Leavetype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Leavetype loadByPrimaryKey( Long primaryKey ) {
       return (Leavetype) hibernateTemplate.get( Leavetype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Leavetype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Leavetype> loadByHql(String query) {
       return ( List<Leavetype> ) hibernateTemplate.find( query );
   }
}